package com.android.taskmanager.volume;

import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.widget.SeekBar;

import com.android.taskmanager.R;

public class Volume extends Activity {
	
	SeekBar alarm=null;
	SeekBar music=null;
	SeekBar ring=null;
	SeekBar system=null;
	SeekBar voice=null;
	AudioManager mgr=null;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_volume);
        
        mgr=(AudioManager)getSystemService(Context.AUDIO_SERVICE);

		alarm=(SeekBar)findViewById(R.id.alarm);
		music=(SeekBar)findViewById(R.id.music);
		ring=(SeekBar)findViewById(R.id.ring);
		system=(SeekBar)findViewById(R.id.system);
		voice=(SeekBar)findViewById(R.id.voice);

		initBar(alarm, AudioManager.STREAM_ALARM);
		initBar(music, AudioManager.STREAM_MUSIC);
		initBar(ring, AudioManager.STREAM_RING);
		initBar(system, AudioManager.STREAM_SYSTEM);
		initBar(voice, AudioManager.STREAM_VOICE_CALL);
    }
    
    private void initBar(SeekBar bar, final int stream) {
		bar.setMax(mgr.getStreamMaxVolume(stream));
		bar.setProgress(mgr.getStreamVolume(stream));

		bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
			public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) {
				mgr.setStreamVolume(stream,	progress,AudioManager.FLAG_PLAY_SOUND);
			}

			public void onStartTrackingTouch(SeekBar bar) {
				// no-op
			}

			public void onStopTrackingTouch(SeekBar bar) {
				// no-op
			}
		});
	}
}

// Hf3Sc2Yq5xU3